package com.hxk.juc.thread.syn8d;

import java.util.concurrent.TimeUnit;

/**
 * //结论，synchronized锁的整个对象，这里必须是ｍ１方法执行完后在执行ｍ２
 */
public class SynchronizedCase1 {

    public synchronized void m1(){
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("m1");
    }

    public synchronized  void m2(){
        System.out.println("m2");
    }

    public static void main(String[] args) throws Exception {
        SynchronizedCase1 case1 = new SynchronizedCase1();
        new Thread(()->{case1.m1();},"001").start();

        new Thread(()->{case1.m2();},"002").start();

    }
}
